#!/usr/bin/ruby
# This program fetches bibtex file for a given PMID
# Usage example: ruby get.bibtex.rb 20176788 >  20176788.bib

require 'bio'

pmid = ARGV[0]

Bio::NCBI.default_email = "jimmysaw@gmail.com"

entries = Bio::PubMed.esearch(pmid)

Bio::PubMed.efetch(entries).each do |entry|
  medline = Bio::MEDLINE.new(entry)
  reference = medline.reference
  puts reference.bibtex
end
